home *** CD-ROM | disk | FTP | other *** search
/ Delphi Magazine Collection 2001 / Delphi Magazine Collection 20001 (2001).iso / DISKS / Issue32 / extlistv / EXTLISTV.ZIP / EnhListView.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1997-10-02  |  19.9 KB  |  647 lines

  1. { -----------------------------------------------------------------------------}
  2. { A list view control that provides enhanced functionality over the standard.  }
  3. { Copyright 1997, Brad Stowers.  All Rights Reserved.                          }
  4. { This component can be freely used and distributed in commercial and private  }
  5. { environments, provied this notice is not modified in any way.                }
  6. { -----------------------------------------------------------------------------}
  7. { Feel free to contact me if you have any questions, comments or suggestions   }
  8. { at bstowers@pobox.com.                                                       }
  9. { The lateset version will always be available on the web at:                  }
  10. {   http://www.pobox.com/~bstowers/delphi/                                     }
  11. { -----------------------------------------------------------------------------}
  12. { Date last modified:  September 12, 1997                                      }
  13. { -----------------------------------------------------------------------------}
  14.  
  15. { -----------------------------------------------------------------------------}
  16. { TEnhListView v3.00 Beta 8                                                    }
  17. { -----------------------------------------------------------------------------}
  18. {                                                                              }
  19. { Description:                                                                 }
  20. {   A list view control that provides enhanced functionality beyond the        }
  21. {   standard list view.  For example, automatic sorting of simple data types,  }
  22. {   owner draw event for vsReport mode, and more.  This does NOT require any   }
  23. {   special version of COMCTL32.DLL.                                           }
  24. {                                                                              }
  25. { -----------------------------------------------------------------------------}
  26. {                                                                              }
  27. { Revision History: (See History.txt for full list)                            }
  28. { 3.00:  Beta 5                                                                }
  29. {        + Initial Public Beta.  Version is 3.00 to match sister component,    }
  30. {          TExtListView, from which most of all of this came from.             }
  31. {        + Removed the DefaultOwnerDrawing property and added a variable       }
  32. {          boolean parameter to the OnDrawItem event that does the same.  This }
  33. {          gives a bit more flexibility, as you can specify on a per item      }
  34. {          basis which should be drawn normally, and which not.                }
  35. {        + Made the Canvas parameter of the OnDrawItem event variable so that  }
  36. {          elements can of it can be changed to affect the default drawing.    }
  37. {          See the EnhDemo project for an example of how to draw an item in    }
  38. {          bold italics in 3 lines of code!                                    }
  39. { Beta 6 + Added an OnAfterDefaultDraw event that fires for owner draw style   }
  40. {          if default drawing is specified after it finishes.                  }
  41. { Beta 7 + Stupid oversight.  Would not compile under Delphi 2.                }
  42. { Beta 8 + Default drawing now occurs for owner draw style if not event        }
  43. {          handler is given for OnDrawItem.                                    }
  44. {------------------------------------------------------------------------------}
  45.  
  46.  
  47. unit EnhListView;
  48.  
  49. interface
  50.  
  51. {$IFNDEF WIN32}
  52.   ERROR!  This unit only available for Delphi 2.0 or higher!!!
  53. {$ENDIF}
  54.  
  55. uses
  56.   Windows, Messages, Classes, Controls, ComCtrls, CommCtrl, SysUtils, Graphics,
  57.   StdCtrls, Menus;
  58.  
  59.  
  60. type
  61.   TIntArray = array[0..(MaxInt div SizeOf(Integer)-1)] of Integer;
  62.   PIntArray = ^TIntArray;
  63.  
  64.  
  65.   TAutoColumnSort = (acsNoSort,acsSort,acsSortToggle);
  66.   TLVStyle = (lvStandard, lvOwnerDrawFixed);
  67.   TLVDrawItemEvent = procedure(Control: TWinControl; var Canvas: TCanvas;
  68.      Index: Integer; Rect: TRect; State: TOwnerDrawState;
  69.      var DefaultDrawing: boolean) of object;
  70.   TLVAfterDrawItemEvent = procedure(Control: TWinControl; var Canvas: TCanvas;
  71.      Index: Integer; Rect: TRect; State: TOwnerDrawState) of object;
  72.   TLVSortItemsEvent = procedure(Sender: TObject; const Item1, Item2: TListItem;
  73.      SortColumn: integer; var CompResult: integer) of object;
  74.  
  75.   { Class for saved settings                                                             }
  76.   TEnhLVSaveSettings = class(TPersistent)
  77.   private
  78.     FAutoSave: boolean;
  79.     FRegistryKey: string;
  80.     FSaveColumnSizes: boolean;
  81.   public
  82.     constructor Create; virtual;
  83.     procedure StoreColumnSizes(ColCount: integer;
  84.        const IntArray: array of integer);
  85.     procedure ReadColumnSizes(ColCount: integer;
  86.        var IntArray: array of integer);
  87.   published
  88.     property AutoSave: boolean read FAutoSave write FAutoSave default FALSE;
  89.     property RegistryKey: string read FRegistryKey write FRegistryKey;
  90.     property SaveColumnSizes: boolean
  91.        read FSaveColumnSizes
  92.        write FSaveColumnSizes
  93.        default TRUE;
  94.   end;
  95.  
  96.  
  97.   { The new class }
  98.   TCustomEnhListView = class(TCustomListView)
  99.   private
  100.     FCanvas: TCanvas;
  101.     FStyle: TLVStyle;
  102.     FAutoColumnSort: TAutoColumnSort;
  103.     FAutoSortAscending: boolean;
  104.     FTmpAutoSortAscending: boolean;
  105.     FLastColumnClicked: Integer;
  106.     FSaveSettings: TEnhLVSaveSettings;
  107.  
  108.     FOnSortBegin: TNotifyEvent;
  109.     FOnSortFinished: TNotifyEvent;
  110.     FOnDrawItem: TLVDrawItemEvent;
  111.     FOnAfterDefaultDrawItem: TLVAfterDrawItemEvent;
  112.     FOnSortItems: TLVSortItemsEvent;
  113.  
  114.     { Message handlers }
  115.     procedure CNDrawItem(var Message: TWMDrawItem); message CN_DRAWITEM;
  116.     procedure WMDestroy(var Message: TWMDestroy); message WM_DESTROY;
  117.   protected
  118.     { Overriden ancestor methods }
  119.     procedure ColClick(Column: TListColumn); override;
  120.     { Property methods }
  121.     procedure SetAutoColumnSort(Value: TAutoColumnSort);
  122.     procedure SetAutoSortAscending(Value: boolean);
  123.     procedure SetStyle(Value: TLVStyle);
  124.  
  125.     procedure CreateParams(var Params: TCreateParams); override;
  126.     procedure Loaded; override;
  127.  
  128.     { Should be published by descendants as needed }
  129.     property AutoColumnSort: TAutoColumnSort
  130.              read FAutoColumnSort
  131.              write SetAutoColumnSort
  132.              default acsNoSort;
  133.     property AutoSortAscending: boolean
  134.              read FAutoSortAscending
  135.              write SetAutoSortAscending
  136.              default TRUE;
  137.     property CurrentSortAscending: boolean
  138.              read FTmpAutoSortAscending;
  139.     property SaveSettings: TEnhLVSaveSettings
  140.              read FSaveSettings
  141.              write FSaveSettings;
  142.     property Style: TLVStyle
  143.              read FStyle
  144.              write SetStyle
  145.              default lvStandard;
  146.  
  147.     { Events }
  148.     property OnDrawItem: TLVDrawItemEvent
  149.              read FOnDrawItem
  150.              write FOnDrawItem;
  151.     property OnAfterDefaultDrawItem: TLVAfterDrawItemEvent
  152.              read FOnAfterDefaultDrawItem
  153.              write FOnAfterDefaultDrawItem;
  154.     property OnSortItems: TLVSortItemsEvent
  155.              read FOnSortItems
  156.              write FOnSortItems;
  157.     property OnSortBegin: TNotifyEvent
  158.              read FOnSortBegin
  159.              write FOnSortBegin;
  160.     property OnSortFinished: TNotifyEvent
  161.              read FOnSortFinished
  162.              write FOnSortFinished;
  163.   public
  164.     constructor Create(AOwner: TComponent); override;
  165.     destructor Destroy; override;
  166.  
  167.     procedure StoreSettings; virtual;
  168.     procedure LoadSettings; virtual;
  169.     procedure DefaultSort(ColumnIndex:integer; Ascending:boolean); virtual;
  170.     procedure Resort; virtual;
  171.   end;
  172.  
  173.  
  174.   TEnhListView = class(TCustomEnhListView)
  175.   published
  176.     property AutoColumnSort;
  177.     property AutoSortAscending;
  178.     property CurrentSortAscending;
  179.     property SaveSettings;
  180.     property Style;
  181.  
  182.     property OnDrawItem;
  183.     property OnAfterDefaultDrawItem;
  184.     property OnSortItems;
  185.     property OnSortBegin;
  186.     property OnSortFinished;
  187.  
  188.     { Publish TCustomListView inherited protected properties }
  189.     property Align;
  190.     property BorderStyle;
  191.     property Color;
  192.     property ColumnClick;
  193.     property OnClick;
  194.     property OnDblClick;
  195.     property Columns;
  196.     property Ctl3D;
  197.     property DragMode;
  198.     property ReadOnly default False;
  199.     property Enabled;
  200.     property Font;
  201.     property HideSelection;
  202.     property IconOptions;
  203.     property Items;
  204.     property AllocBy;
  205.     property MultiSelect;
  206.     property OnChange;
  207.     property OnChanging;
  208.     property OnColumnClick;
  209.     property OnCompare;
  210.     property OnDeletion;
  211.     property OnEdited;
  212.     property OnEditing;
  213.     property OnEnter;
  214.     property OnExit;
  215.     property OnInsert;
  216.     property OnDragDrop;
  217.     property OnDragOver;
  218.     property DragCursor;
  219.     property OnStartDrag;
  220.     property OnEndDrag;
  221.     property OnMouseDown;
  222.     property OnMouseMove;
  223.     property OnMouseUp;
  224.     property ParentColor default False;
  225.     property ParentFont;
  226.     property ParentShowHint;
  227.     property ShowHint;
  228.     property PopupMenu;
  229.     property ShowColumnHeaders;
  230.     property SortType;
  231.     property TabOrder;
  232.     property TabStop default True;
  233.     property ViewStyle;
  234.     property Visible;
  235.     property OnKeyDown;
  236.     property OnKeyPress;
  237.     property OnKeyUp;
  238.     property LargeImages;
  239.     property SmallImages;
  240.     property StateImages;
  241.   end;
  242.  
  243. var
  244.   { Default drawing variables }
  245.   DefDraw_TextOffset: integer; // Offset for the text -- 5
  246.   DefDraw_ImageOffset: integer; // Offset for image -- 2
  247.   DefDraw_TextOffsetWithImage: integer; // Offset for text with image -- 20
  248.  
  249.  
  250. implementation
  251.  
  252. uses
  253.   Registry;
  254.  
  255.  
  256. var
  257.   FDirection,
  258.   FSortColNum: integer;
  259.  
  260. function __CustomSortProc1__(Item1, Item2: TListItem; Data: integer): integer; stdcall;
  261.  
  262.   function IsValidNumber(const S: string; var V: extended): boolean;
  263.   var
  264.     NumCode: integer;
  265.   begin
  266.     Val(S, V, NumCode);
  267.     Result := (NumCode = 0);
  268.   end;
  269.  
  270.   function IsValidDate(const S: string; var D: TDateTime): boolean;
  271.   begin
  272.     if Pos (DateSeparator, S) = 0 then
  273.       Result := False
  274.     else                        // will fail if using a long date format
  275.       try                        // e.g., '1 January 1994'
  276.         D := StrToDate(S);
  277.         Result := TRUE;
  278.       except
  279.         D := 0;
  280.         Result := FALSE;
  281.       end
  282.   end;
  283.  
  284. var
  285.   Str1, Str2: string;
  286.   Val1, Val2: extended;
  287.   Date1, Date2: TDateTime;
  288. begin
  289.   try
  290.     if FSortColNum = -1 then begin
  291.       Str1 := Item1.Caption;
  292.       Str2 := Item2.Caption;
  293.     end else begin
  294.       Str1 := Item1.SubItems[FSortColNum];
  295.       Str2 := Item2.SubItems[FSortColNum];
  296.     end;
  297.  
  298.     if IsValidDate(Str1, Date1) and IsValidDate(Str2, Date2) then
  299.       Result := Trunc(Date1 - Date2)
  300.     else if IsValidNumber(Str1, Val1) and IsValidNumber(Str2, Val2) then
  301.       if   Val1 < Val2 then Result := -1
  302.       else if Val1 > Val2 then Result := 1
  303.       else Result := 0
  304.     else // date check?
  305.       Result := AnsiCompareStr(Str1, Str2);
  306.  
  307.  
  308.     Result := FDirection * Result; // Set direction flag.
  309.   except
  310.     Result := 0;  // Something went bad in the comparison.  Say they are equal.
  311.   end;
  312. end;
  313.  
  314. function __CustomSortProc2__(Item1, Item2: TListItem; Data: integer): integer; stdcall;
  315. var
  316.   EvRes: integer;
  317. begin
  318.   EvRes := 0;
  319.   TCustomEnhListView(Data).FOnSortItems(TObject(Data), Item1, Item2,
  320.      FSortColNum, EvRes);
  321.   Result := EvRes * FDirection;
  322. end;
  323.  
  324. constructor TEnhLVSaveSettings.Create;
  325. begin
  326.   FAutoSave := FALSE;
  327.   FRegistryKey := '';
  328.   FSaveColumnSizes := TRUE;
  329. end;
  330.  
  331. procedure TEnhLVSaveSettings.StoreColumnSizes(ColCount: integer;
  332.    const IntArray: array of integer);
  333. var
  334.   Reg: TRegIniFile;
  335.   x: integer;
  336.   s: string;
  337. begin
  338.   if ColCount < 1 then exit;
  339.   s := '';
  340.   for x := 0 to ColCount-1 do
  341.     s := s + IntToStr(IntArray[x]) + ',';
  342.   SetLength(s, Length(s)-1);
  343.   Reg := TRegIniFile.Create(FRegistryKey);
  344.   try
  345.     Reg.WriteString('Columns', 'Sizes', s);
  346.   finally
  347.     Reg.Free;
  348.   end;
  349. end;
  350.  
  351. procedure TEnhLVSaveSettings.ReadColumnSizes(ColCount: integer;
  352.    var IntArray: array of integer);
  353. var
  354.   Reg: TRegIniFile;
  355.   x,y: integer;
  356.   s: string;
  357. begin
  358.   if ColCount < 1 then exit;
  359.   s := '';
  360.   Reg := TRegIniFile.Create(FRegistryKey);
  361.   try
  362.     s := Reg.ReadString('Columns', 'Sizes', '');
  363.   finally
  364.     Reg.Free;
  365.   end;
  366.   if s = '' then begin
  367.     IntArray[0] := -1;
  368.     exit;
  369.   end;
  370.   y := 0;
  371.   for x := 0 to ColCount-1 do begin
  372.     try
  373.       y := Pos(',', s);
  374.       if y = 0 then
  375.         y := Length(s)+1;
  376.       IntArray[x] := StrToInt(Copy(s, 1, y-1));
  377.     except
  378.       IntArray[x] := 0;
  379.     end;
  380.     s := copy(s, y+1, length(s));
  381.     if s = '' then break;
  382.   end;
  383. end;
  384.  
  385. { Override constructor to "zero out" our internal variable.                              }
  386. constructor TCustomEnhListView.Create(AOwner: TComponent);
  387. begin
  388.   inherited Create(AOwner);
  389.  
  390.   FSaveSettings := TEnhLVSaveSettings.Create;
  391.   FAutoColumnSort := acsNoSort;
  392.   FAutoSortAscending := TRUE;
  393.   FTmpAutoSortAscending := FAutoSortAscending;
  394.   FLastColumnClicked := -1;
  395.   FCanvas := NIL;
  396.   FStyle  := lvStandard;
  397. end;
  398.  
  399. destructor TCustomEnhListView.Destroy;
  400. begin
  401.   FCanvas.Free;
  402.   FSaveSettings.Free;
  403.  
  404.   inherited Destroy;
  405. end;
  406.  
  407. procedure TCustomEnhListView.CreateParams(var Params: TCreateParams);
  408. begin
  409.   inherited CreateParams(Params);
  410.  
  411.   if FStyle = lvOwnerDrawFixed then
  412.   begin
  413.     Params.Style := Params.Style or LVS_OWNERDRAWFIXED;
  414.     if FCanvas = NIL then
  415.       FCanvas := TCanvas.Create;
  416.   end else begin
  417.     FCanvas.Free;
  418.     FCanvas := NIL;
  419.   end;
  420. end;
  421.  
  422. procedure TCustomEnhListView.Loaded;
  423. begin
  424.   inherited Loaded;
  425.  
  426.   LoadSettings;
  427. end;
  428.  
  429. procedure TCustomEnhListView.WMDestroy(var Message: TWMDestroy);
  430. begin
  431.   StoreSettings;
  432.  
  433.   inherited;
  434. end;
  435.  
  436. procedure TCustomEnhListView.StoreSettings;
  437. var
  438.   ColCount: integer;
  439.   ColArray: PIntArray;
  440.   x: integer;
  441. begin
  442.   if FSaveSettings.AutoSave and (not(csDesigning in ComponentState)) then begin
  443.     ColCount := Columns.Count;
  444.     if ColCount > 0 then begin
  445.       GetMem(ColArray, SizeOf(Integer)*ColCount);
  446.       try
  447.         if FSaveSettings.SaveColumnSizes then begin
  448.           for x := 0 to ColCount-1 do
  449.             ColArray[x] := Columns[x].Width;
  450.           FSaveSettings.StoreColumnSizes(ColCount, ColArray^);
  451.         end;
  452.       finally
  453.         FreeMem(ColArray);
  454.       end;
  455.     end;
  456.   end;
  457. end;
  458.  
  459. procedure TCustomEnhListView.LoadSettings;
  460. var
  461.   ColCount: integer;
  462.   ColArray: PIntArray;
  463.   x: integer;
  464. begin
  465.   if FSaveSettings.AutoSave and (not(csDesigning in ComponentState)) then begin
  466.     ColCount := Columns.Count;
  467.     if ColCount > 0 then begin
  468.       GetMem(ColArray, SizeOf(Integer)*ColCount);
  469.       try
  470.         if FSaveSettings.SaveColumnSizes then begin
  471.           FSaveSettings.ReadColumnSizes(ColCount, ColArray^);
  472.           if ColArray[0] <> -1 then
  473.             for x := 0 to ColCount-1 do
  474.               Columns[x].Width := ColArray[x];
  475.         end;
  476.       finally
  477.         FreeMem(ColArray);
  478.       end;
  479.     end;
  480.   end;
  481. end;
  482.  
  483. procedure TCustomEnhListView.DefaultSort(ColumnIndex: integer;
  484.    Ascending: boolean);
  485. begin
  486.   if assigned(FOnSortBegin) then
  487.     FOnSortBegin(Self);
  488.   if Ascending then
  489.     FDirection := 1
  490.   else
  491.     FDirection := -1;
  492.   FSortColNum := ColumnIndex - 1;
  493.   if assigned(FOnSortItems) then
  494.     CustomSort(@__CustomSortProc2__, integer(Self))
  495.   else
  496.     CustomSort(@__CustomSortProc1__, 0);
  497.   if assigned(FOnSortFinished) then
  498.     FOnSortFinished(Self);
  499. end;
  500.  
  501. procedure TCustomEnhListView.ColClick(Column: TListColumn);
  502. begin
  503.   // Check if the sort order should be toggled
  504.   if FAutoColumnSort = acsSortToggle then
  505.     if FLastColumnClicked = Column.Index then
  506.       FTmpAutoSortAscending := not FTmpAutoSortAscending
  507.     else
  508.       FTmpAutoSortAscending := FAutoSortAscending;
  509.  
  510.   inherited ColClick(Column);
  511.  
  512.   if (FAutoColumnSort <> acsNoSort) and (Column.Index < Columns.Count) then
  513.   begin
  514.     DefaultSort(Column.Index, FTmpAutoSortAscending);
  515.     FLastColumnClicked := Column.Index;
  516.   end;
  517. end;
  518.  
  519. procedure TCustomEnhListView.SetAutoColumnSort(Value: TAutoColumnSort);
  520. begin
  521.   if FAutoColumnSort <> Value then
  522.     FAutoColumnSort := Value;
  523. end;
  524.  
  525. procedure TCustomEnhListView.SetAutoSortAscending(Value: Boolean);
  526. begin
  527.   if FAutoSortAscending <> Value then begin
  528.     FAutoSortAscending := Value;
  529.     FTmpAutoSortAscending := Value;
  530.   end;
  531. end;
  532.  
  533. procedure TCustomEnhListView.Resort;
  534. begin
  535.   if (FAutoColumnSort <> acsNoSort) and (FLastColumnClicked >= 0) and
  536.      (FLastColumnClicked < Columns.Count) then
  537.     DefaultSort(FLastColumnClicked, FTmpAutoSortAscending);
  538. end;
  539.  
  540. procedure TCustomEnhListView.CNDrawItem(var Message: TWMDrawItem);
  541.   procedure DrawItem(Index: Integer; Rect: TRect;State: TOwnerDrawState);
  542.   const
  543.     DRAWTEXT_FLAGS = DT_LEFT or DT_NOPREFIX or DT_SINGLELINE or DT_VCENTER;
  544.   var
  545.     Count: Integer;
  546.     SubRect: TRect;
  547.   begin
  548.     SubRect := Rect;
  549.     if assigned(SmallImages) then
  550.     begin
  551.       if odFocused in State then
  552.         SmallImages.DrawingStyle := dsFocus
  553.       else if odSelected in State then
  554.         SmallImages.DrawingStyle := dsSelected
  555.       else
  556.         SmallImages.DrawingStyle := dsNormal;
  557.       SmallImages.Draw(FCanvas, Rect.Left + DefDraw_ImageOffSet, Rect.Top,
  558.                        Items[Index].ImageIndex);
  559.       SubRect.Right := Rect.Left + Column[0].Width;
  560.       inc(SubRect.Left, DefDraw_TextOffsetWithImage);
  561.       DrawText(FCanvas.Handle, PChar(Items[Index].Caption), -1, SubRect,
  562.          DRAWTEXT_FLAGS);
  563.     end else begin
  564.       SubRect.Right := Rect.Left + Column[0].Width;
  565.       inc(SubRect.Left, DefDraw_TextOffset);
  566.       DrawText(FCanvas.Handle, PChar(Items[Index].Caption), -1, SubRect,
  567.          DRAWTEXT_FLAGS);
  568.     end;
  569.  
  570.     for Count := 0 to Items[Index].Subitems.Count-1 do
  571.     begin
  572.       SubRect.Left := SubRect.Right;
  573.       SubRect.Right := SubRect.Left + Column[Count+1].Width;
  574.       Inc(SubRect.Left, DefDraw_TextOffset);
  575.       DrawText(FCanvas.Handle, PChar(Items[Index].SubItems[Count]), -1,
  576.          SubRect, DRAWTEXT_FLAGS);
  577.     end;
  578.   end;
  579. var
  580.   State: TOwnerDrawState;
  581.   SubRect: TRect;
  582.   DoDefaultDrawing: boolean;
  583. begin { CNDrawItem }
  584.   If FCanvas = NIL then exit;
  585.  
  586.   with Message.DrawItemStruct^ do
  587.   begin
  588.     State := TOwnerDrawState(WordRec(LongRec(itemState).Lo).Lo);
  589.     FCanvas.Handle := hDC;
  590.     FCanvas.Font := Font;
  591.     FCanvas.Brush := Brush;
  592.  
  593.     DoDefaultDrawing := FALSE;
  594.     if (not (csDesigning in ComponentState)) and assigned(FOnDrawItem) then
  595.       FOnDrawItem(Self, FCanvas, itemID, rcItem, State, DoDefaultDrawing)
  596.     else
  597.       DoDefaultDrawing := not assigned(FOnDrawItem);
  598.  
  599.     if DoDefaultDrawing or (csDesigning in ComponentState) then begin
  600.       FCanvas.FillRect(rcItem);
  601.       if (integer(itemID) >= 0) then
  602.       begin
  603.         if (odSelected in State) then
  604.         begin
  605.           FCanvas.Brush.Color := clHighlight;
  606.           FCanvas.Font.Color := clHighlightText;
  607.           SubRect := rcItem;
  608.           if assigned(SmallImages) then
  609.             Inc(SubRect.Left, SmallImages.Width+2);
  610.           FCanvas.FillRect(SubRect);
  611.         end;
  612.         DrawItem(itemID, rcItem, State);
  613.         if (odFocused in State) then
  614.         begin
  615.           SubRect := rcItem;
  616.           if assigned(SmallImages) then
  617.             Inc(SubRect.Left, SmallImages.Width+2);
  618.           FCanvas.DrawFocusRect(SubRect);
  619.         end;
  620.       end else
  621.         FCanvas.FillRect(rcItem);
  622.       if (not (csDesigning in ComponentState)) and assigned(FOnAfterDefaultDrawItem) then
  623.         FOnAfterDefaultDrawItem(Self, FCanvas, itemID, rcItem, State);
  624.  
  625.     end;
  626.     FCanvas.Handle := 0;
  627.   end;
  628. end;
  629.  
  630. procedure TCustomEnhListView.SetStyle(Value: TLVStyle);
  631. begin
  632.   if FStyle <> Value then
  633.   begin
  634.     FStyle := Value;
  635.     RecreateWnd;
  636.   end;
  637. end;
  638.  
  639.  
  640.  
  641. initialization
  642.   DefDraw_TextOffset := 5;
  643.   DefDraw_ImageOffset := 2;
  644.   DefDraw_TextOffsetWithImage := 20;
  645. end.
  646.  
  647.